package cs342.uwosh.group1.mycontacts.Threads;

import java.util.ArrayList;
import java.util.List;

import com.mycontacts.R;
import com.mycontacts.R.id;
import com.mycontacts.R.layout;

import cs342.uwosh.group1.mycontacts.Contact;
import cs342.uwosh.group1.mycontacts.MainActivity;
import cs342.uwosh.group1.mycontacts.SqlConnect;

import android.os.AsyncTask;
import android.widget.ArrayAdapter;


public class GetAllContactTask extends AsyncTask<Object, Object, ArrayList<Contact>>{

	
	@Override
	protected ArrayList<Contact> doInBackground(Object... arg0) {

		SqlConnect db = MainActivity.db;
		
		return (ArrayList<Contact>)db.getAll();
	}
	
	/**
	 * 
	 */
	protected void onPostExecute(ArrayList<Contact> result)
	{
		ArrayList<Contact> contacts = result;

        for(Contact c: contacts)
        {
        	MainActivity.allContacts.put(""+c.getId(), c);
        }

        MainActivity.contactListAdapter = new ArrayAdapter<Contact>(MainActivity.mainContext, R.layout.list_item, R.id.contactItem, contacts);
        
        MainActivity.listOfContacts.setAdapter(MainActivity.contactListAdapter);
	}
}